package com.qianfeng.xinyihezi.xinyihezi.activity.activity_meng;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.EditText;
import android.widget.TextView;

import com.qianfeng.xinyihezi.xinyihezi.R;
import com.qianfeng.xinyihezi.xinyihezi.model.bean_meng.Address;

public class AddAddressActivity extends AppCompatActivity implements View.OnClickListener {
    private EditText mEditTextName, mEditTextArea, mEditTextNumber, mEditTextEmail, mEditTextPhone;
    private TextView mTextViewBack, mTextViewSave;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_add_address);
        initView();
        setListener();
    }

    private void initView() {
        mEditTextName = (EditText) findViewById(R.id.et_edit_name);
        mEditTextArea = (EditText) findViewById(R.id.et_edit_area);
        mEditTextNumber = (EditText) findViewById(R.id.et_edit_number);
        mEditTextEmail = (EditText) findViewById(R.id.et_edit_email);
        mEditTextPhone = (EditText) findViewById(R.id.et_edit_phone);

        mTextViewBack = (TextView) findViewById(R.id.tv_add_finish);
        mTextViewSave = (TextView) findViewById(R.id.tv_add_save);
    }

    private void setListener() {
        mTextViewSave.setOnClickListener(this);
        mTextViewBack.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_add_finish:
                finish();
                break;
            case R.id.tv_add_save:
                Address address = new Address();
                address.name = mEditTextName.getText().toString();
                address.area = mEditTextArea.getText().toString();
                address.number = mEditTextNumber.getText().toString();
                address.postcode = mEditTextEmail.getText().toString();
                address.phone = mEditTextPhone.getText().toString();
                address.save();
                break;
            default:
                break;
        }
    }
}
